﻿namespace Huayou.UI.WebControls
{
    using System;
    using System.Web.UI;
    using System.Xml;

    internal class MenuItemIE4 : MenuItemRenderBase
    {
        public MenuItemIE4(XmlElement node, MenuGroup parentGroup, WebMenu menu) : base(node, parentGroup, menu)
        {
        }

        protected string generateSubGroupCollapse()
        {
            string str = "";
            if (base.ItemNode.HasChildNodes && base.Menu.Enabled)
            {
                str = (((("if (document.readyState == 'complete') aspnm_itemMsOut('" + base.ClientSideID + "', '") + base.ParentGroup.ClientSideID + "', '") + base.ItemNode.ChildNodes[0].Attributes["ClientSideID"].Value + "', ") + base.Menu.ExpandDelay.ToString() + ", ") + base.getCollapseEffect() + ");";
            }
            return str;
        }

        protected string generateSubGroupExpand()
        {
            string str2;
            string str = "";
            if (!base.ItemNode.HasChildNodes || !base.Menu.Enabled)
            {
                return str;
            }
            if ((base.ItemNode.ChildNodes[0].Attributes["ExpandDirection"] != null) && (base.Menu.MenuStyle == WebMenuStyle.FreeStyle))
            {
                str2 = base.ItemNode.ChildNodes[0].Attributes["ExpandDirection"].Value.ToLower();
            }
            else if ((base.ItemNode.ParentNode.ParentNode.Name == "MenuData") && (base.Menu.MenuStyle == WebMenuStyle.ClassicHorizontal))
            {
                str2 = "belowleft";
            }
            else
            {
                str2 = "rightdown";
            }
            string str3 = "0";
            string str4 = "0";
            if (base.ItemNode.ChildNodes[0].Attributes["ExpandOffsetX"] != null)
            {
                str3 = base.ItemNode.ChildNodes[0].Attributes["ExpandOffsetX"].Value;
            }
            if (base.ItemNode.ChildNodes[0].Attributes["ExpandOffsetY"] != null)
            {
                str4 = base.ItemNode.ChildNodes[0].Attributes["ExpandOffsetY"].Value;
            }
            string str5 = base.getExpandEffect();
            return ((((((("if (document.readyState == 'complete') aspnm_itemMsOver('" + base.ClientSideID + "', '") + base.ItemNode.ChildNodes[0].Attributes["ClientSideID"].Value + "', '") + str2 + "', ") + str3 + ", ") + str4 + ", ") + base.Menu.ExpandDelay.ToString() + ", ") + str5 + ");");
        }

        public override void RenderCssItem(HtmlTextWriter output)
        {
            output.AddAttribute("class", base.CssClass);
            string str = "";
            string str2 = "";
            string str3 = "";
            string str4 = "";
            string str5 = "";
            if (base.CssClassOver != null)
            {
                str = "this.className='" + base.CssClassOver + "';";
                str2 = "this.className='" + base.CssClass + "';";
            }
            str = str + this.generateSubGroupExpand();
            str2 = str2 + this.generateSubGroupCollapse();
            if (base.ItemType == "grip")
            {
                str = str + "this.style.cursor='move';";
                str3 = "aspnm_startDragging('" + base.Menu.ClientID + "');";
                output.AddAttribute("onmouseup", "aspnm_stopDragging();");
                base.Menu.IsMovable = true;
            }
            if (str != "")
            {
                output.AddAttribute("onmouseover", str);
                output.AddAttribute("onmouseout", str2);
            }
            if (base.CssClassDown != null)
            {
                str3 = str3 + "this.className='" + base.CssClassDown + "';";
                str4 = str4 + "this.className='" + base.CssClassOver + "';";
            }
            if (str3 != "")
            {
                output.AddAttribute("onmousedown", str3);
                output.AddAttribute("onmouseup", str4);
            }
            output.AddAttribute("onmousemove", "return false;");
            output.AddAttribute("ondblclick", "return false;");
            str5 = base.generateClickCommand();
            if (str5 != "")
            {
                output.AddAttribute("onclick", str5);
            }
            if (base.Width != null)
            {
                output.AddAttribute("width", base.Width.ToString());
            }
            if (base.Height != null)
            {
                output.AddAttribute("height", base.Height.ToString());
            }
            if (base.ClientSideID != null)
            {
                output.AddAttribute("id", base.ClientSideID);
            }
            if (base.TextAlign != null)
            {
                output.AddAttribute("align", base.TextAlign);
            }
            output.RenderBeginTag("td");
            if (base.NoWrap)
            {
                output.Write("<nobr>" + base.Label + "</nobr>");
            }
            else
            {
                output.Write(base.Label);
            }
            output.RenderEndTag();
        }

        public override void RenderIconItem(HtmlTextWriter output)
        {
            string str;
            string str2;
            string str8;
            if (base.Width != null)
            {
                output.AddAttribute("width", base.Width.ToString());
            }
            if (base.Height != null)
            {
                output.AddAttribute("height", base.Height.ToString());
            }
            output.RenderBeginTag("td");
            if (base.CssClass != null)
            {
                output.AddAttribute("class", base.CssClass);
            }
            output.AddAttribute("id", base.ClientSideID);
            output.AddAttribute("cellpadding", "0");
            output.AddAttribute("cellspacing", "0");
            output.AddAttribute("border", "0");
            output.AddAttribute("width", "100%");
            output.AddAttribute("height", "100%");
            if (base.LeftIcon != null)
            {
                base.Menu.IconCount++;
                str = "'" + base.Menu.ClientID + "_icon_" + base.Menu.IconCount.ToString() + "'";
            }
            else
            {
                str = "null";
            }
            if (base.RightIcon != null)
            {
                base.Menu.IconCount++;
                str2 = "'" + base.Menu.ClientID + "_icon_" + base.Menu.IconCount.ToString() + "'";
            }
            else
            {
                str2 = "null";
            }
            string str3 = "";
            string str4 = "";
            if (((base.CssClassOver != null) || (base.LeftIconOver != null)) || (base.RightIconOver != null))
            {
                str8 = "if (document.readyState == 'complete') aspnm_updateCell('" + base.ClientSideID + "', '" + base.CssClassOver + "', ";
                str3 = str8 + str + ", '" + base.LeftIconOver + "', " + str2 + ", '" + base.RightIconOver + "', 'over');";
                str8 = "if (document.readyState == 'complete') aspnm_updateCell('" + base.ClientSideID + "', '" + base.CssClass + "', ";
                str4 = str8 + str + ", '" + base.LeftIcon + "', " + str2 + ", '" + base.RightIcon + "', 'out');";
            }
            str3 = str3 + this.generateSubGroupExpand();
            str4 = str4 + this.generateSubGroupCollapse();
            string str5 = "";
            string str6 = "";
            if (((base.CssClassDown != null) || (base.LeftIconDown != null)) || (base.RightIconDown != null))
            {
                str8 = "if (document.readyState == 'complete') aspnm_updateCell('" + base.ClientSideID + "', '" + base.CssClassDown + "', ";
                str5 = str8 + str + ", '" + base.LeftIconDown + "', " + str2 + ", '" + base.RightIconDown + "', 'down');";
                str8 = "if (document.readyState == 'complete') aspnm_updateCell('" + base.ClientSideID + "', '" + base.CssClassOver + "', ";
                str6 = str8 + str + ", '" + base.LeftIconOver + "', " + str2 + ", '" + base.RightIcon + "', 'down');";
            }
            if (base.ItemType == "grip")
            {
                str3 = str3 + "this.style.cursor='move';";
                str5 = str5 + "aspnm_startDragging('" + base.Menu.ClientID + "');";
                output.AddAttribute("onmouseup", "aspnm_stopDragging();");
                base.Menu.IsMovable = true;
            }
            if (str3 != "")
            {
                output.AddAttribute("onmouseover", str3);
                output.AddAttribute("onmouseout", str4);
            }
            if (str5 != null)
            {
                output.AddAttribute("onmousedown", str5);
                output.AddAttribute("onmouseup", str6);
            }
            output.AddAttribute("onmousemove", "return false;");
            output.AddAttribute("ondblclick", "return false;");
            string str7 = base.generateClickCommand();
            if (str7 != "")
            {
                output.AddAttribute("onclick", str7);
            }
            output.RenderBeginTag("table");
            output.RenderBeginTag("tr");
            if (base.LeftIcon != null)
            {
                output.Write(string.Concat(new object[] { "<td style=\"padding:0;\" width=", base.ParentGroup.MaxLeftIconWidth, "><img id=", str, " src=\"", base.LeftIcon, "\" border=0></td>" }));
            }
            else if (base.ParentGroup.MaxLeftIconWidth != 0)
            {
                output.Write("<td style=\"padding:0;\" width=" + base.ParentGroup.MaxLeftIconWidth + "></td>");
            }
            if (base.Image != null)
            {
                this.RenderImageItem(output);
            }
            else
            {
                output.Write("<td");
                if (base.TextAlign != null)
                {
                    output.Write(" align=" + base.TextAlign);
                }
                if (base.NoWrap)
                {
                    output.Write("><nobr>" + base.Label + "</nobr></td>");
                }
                else
                {
                    output.Write(">" + base.Label + "</td>");
                }
            }
            if (base.RightIcon != null)
            {
                output.Write(string.Concat(new object[] { "<td align=right style=\"padding:0;\" width=", base.ParentGroup.MaxRightIconWidth, "><img id=", str2, " src=\"", base.RightIcon, "\" border=0></td>" }));
            }
            else if (base.ParentGroup.MaxRightIconWidth != 0)
            {
                output.Write("<td align=right style=\"padding:0;\" width=" + base.ParentGroup.MaxRightIconWidth + "></td>");
            }
            output.RenderEndTag();
            output.RenderEndTag();
            output.RenderEndTag();
        }

        public override void RenderImageItem(HtmlTextWriter output)
        {
            string str = "<td";
            if (base.Width != null)
            {
                str = str + " width=" + base.Width.ToString();
            }
            if (base.Height != null)
            {
                str = str + " height=" + base.Height.ToString();
            }
            if (base.ClientSideID != null)
            {
                str = str + " id=" + base.ClientSideID;
            }
            string str2 = "";
            string str3 = "";
            string str4 = "";
            string str5 = "";
            str2 = this.generateSubGroupExpand();
            str3 = this.generateSubGroupCollapse();
            if (str2 != "")
            {
                str = (str + " onmouseover=\"" + str2 + "\"") + " onmouseout=\"" + str3 + "\"";
            }
            str = str + ">";
            string str6 = base.generateClickCommand();
            if (str6 != "")
            {
                str = str + "<a href=javascript:" + str6 + ">";
            }
            str = str + "<img src=\"" + base.Image + "\" border=0";
            if (base.Width != null)
            {
                str = str + " width=" + base.Width.ToString();
            }
            if (base.Height != null)
            {
                str = str + " height=" + base.Height.ToString();
            }
            if (base.CssClass != null)
            {
                str = str + " class=" + base.CssClass;
            }
            if (base.ImageOver != null)
            {
                str2 = "this.src='" + base.ImageOver + "';";
                str3 = "this.src='" + base.Image + "';";
            }
            if (base.CssClassOver != null)
            {
                str2 = str2 + "this.className='" + base.CssClassOver + "';";
                str3 = str3 + "this.className='" + base.CssClass + "';";
            }
            if (base.ItemType == "grip")
            {
                str2 = str2 + "this.style.cursor='move';";
                str4 = "aspnm_startDragging('" + base.Menu.ClientID + "');";
                str5 = "aspnm_stopDragging();";
                base.Menu.IsMovable = true;
            }
            if (str2 != "")
            {
                str = (str + " onmouseover=\"" + str2 + "\"") + " onmouseout=\"" + str3 + "\"";
            }
            if (base.ImageDown != null)
            {
                str4 = str4 + "this.src='" + base.ImageDown + "';";
                str5 = str5 + "this.src='" + base.ImageOver + "';";
            }
            if (base.CssClassDown != null)
            {
                str4 = str4 + "this.className='" + base.CssClassDown + "';";
            }
            if (str4 != "")
            {
                str = str + " onmousedown=\"" + str4 + "\"";
            }
            if (str5 != "")
            {
                str = str + " onmouseup=\"" + str5 + "\"";
            }
            str = str + " onmousemove=\"return false;\"" + " ondblclick=\"return false;\"";
            output.AddAttribute("onmousemove", "return false;");
            str = str + ">";
            if (str6 != "")
            {
                str = str + "</a>";
            }
            str = str + "</td>";
            output.Write(str);
        }
    }
}

